/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import Modelo.Hotel;
import java.util.List;

/**
 *
 * @author kassio
 */
public class DaoHotel extends Dao<Hotel>{
    
    public DaoHotel() {
        super();
    }

    @Override
    public List<Hotel> findAll() {
        return getRepositorio().getHoteis();
    }

    @Override
    public Hotel find(Object key) {
        for (Hotel h : getRepositorio().getHoteis()) {
            if (h.getId() == (Integer) key)
                return h;
        }
        return null;
    }

    @Override
    public boolean remove(Hotel obj) {
        Hotel hotel = find(obj.getId());
        boolean remove = getRepositorio().getHoteis().remove(hotel);
        salvarRepositorio();
        return remove;
    }

    @Override
    public boolean add(Hotel obj) {
        List<Hotel> lista = getRepositorio().getHoteis();
        int indice = (lista.size())-1;
        
        if (indice >= 0)
            obj.setId(lista.get(indice).getId()+1);            
        else
            obj.setId(1);
        
        boolean add = getRepositorio().getHoteis().add(obj);
        salvarRepositorio();
        return add;
    }

    @Override
    public void edit(Hotel obj) {
        Hotel temp = find(obj.getId());
        temp.getData(obj);
        salvarRepositorio();
    }
    
    
}
